package tcts0421;
// https://leetcode-cn.com/problems/search-insert-position/
public class 搜索插入位置0424 {

        public int searchInsert(int[] nums, int target) {

            int left = 0;
            int right = nums.length-1;
            int mid = 0;
            while(left<=right){
                mid = left+(right-left)/2;
                if(nums[mid]>target){
                    right = mid-1;
                }else if(nums[mid]<target){
                    left = mid+1;
                }else{
                    return mid;
                }

            }
            return left;
        }


    public static void main(String[] args) {
        System.out.println(new 搜索插入位置0424().searchInsert(new int[]{1, 3, 5, 6}, 5));
    }
}
